package com.example.shop.generator.utils;

import org.apache.commons.lang3.StringUtils;

/**
 * Created by an on 2016/9/26.
 */
public class DataType {

    private static final String ID = "id";
    private static final String CREATE_BY = "createBy";
    private static final String CREATE_DATE = "createDate";
    private static final String UPDATE_BY = "updateBy";
    private static final String UPDATE_DATE = "updateDate";
    private static final String REMARKS = "remarks";
    private static final String DEL_FLAG = "delFlag";

    public String getNewDataType(String typeName) {
        // 设置字段类型
        if (typeName.equals("char")
                || typeName.equals("varchar")
                || typeName.equals("text")
                || typeName.equals("longtext")
                || typeName.equals("narchar")) {
            return "String";
        }

        if (typeName.equals("datetime")
                || typeName.equals("date")
                || typeName.equals("timestamp")) {
            return "Date";
        }

        if (typeName.equals("bigint")
                || typeName.equals("number")) {
            return "Double";
        }

        if (typeName.equals("int")) {
            return "Integer";
        }

        if (typeName.equals("decimal")) {
            return "BigDecimal";
        }

        if (typeName.equals("") || typeName == null) {
            return "Long";
        } else {
            return null;
        }
    }

    public static boolean isFilterOut(String field) {
        if (StringUtils.equals(ID, field)) {
            return false;
        }
        if (StringUtils.equals(CREATE_BY, field)) {
            return false;
        }
        if (StringUtils.equals(CREATE_DATE, field)) {
            return false;
        }
        if (StringUtils.equals(UPDATE_BY, field)) {
            return false;
        }
        if (StringUtils.equals(UPDATE_DATE, field)) {
            return false;
        }
        if (StringUtils.equals(REMARKS, field)) {
            return false;
        }
        if (StringUtils.equals(DEL_FLAG, field)) {
            return false;
        }
        return true;
    }

}
